package com.leon.alishop.web.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.web.bind.annotation.ModelAttribute;

import com.leon.alishop.core.config.AlishopConstant;

/**
 * 定义了几个通用的参数<br>
 * 请在开发环境中添加 -Ddevelop=1 开启开发环境域名<br>
 * @author Leon
 */
public class BaseController {

	/**
	 * 获取当前请求的路径
	 * @param req
	 * @return
	 */
	@ModelAttribute("requestUrl")
	public String getRequestUrl(HttpServletRequest req){
		if(AlishopConstant.isDevelop()){
			return AlishopConstant.HTTP_SCHEMA + "://"
				+ req.getServerName()
				+ (80 == req.getServerPort() ? "" : ":"+req.getServerPort())
				+ req.getContextPath()+"/";
		}
		return AlishopConstant.HTTP_SCHEMA + "://"
		+ req.getServerName()
		+ (80 == req.getServerPort() ? "" : ":"+req.getServerPort())
		+ req.getContextPath()+"/";
//		return AlishopConstant.HTTP_SCHEMA + "://" + req.getServerName()+"/";
	}
	
	/**
	 * 获取静态资源路径
	 * @return
	 */
	@ModelAttribute("staticUrl")
	public String getStaticUrl(HttpServletRequest req){
		return getRequestUrl(req);
	}
	
	
	
	@ModelAttribute("developStatus")
	public boolean isDevelopStatus(HttpServletRequest req){
		return AlishopConstant.isDevelop();
	}
	
	
	
}
